package com.netty.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

/**
 * Scattering:将数据依次写入到buffer时,可以采用buffer数据,依次写入,即当一个buffer满了可以再写到另外一个buffer
 * Gettering:从buffer读取数据时,可以采用buffer数组,依次读取,即读完一个就读下一个
 */
public class ScatteringAndGetteringTest {

    public static void main(String[] args) throws IOException {
        //使用serversocketChannel 和socketChannel 网络的方式
        //1.创建服务端的channel
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        //指定端口
        InetSocketAddress inetSocketAddress = new InetSocketAddress(7000);
        //绑定端口到socket,并启动
        serverSocketChannel.socket().bind(inetSocketAddress);
        //创建buffer数组
        ByteBuffer[] byteBuffers = new ByteBuffer[2];
        //分配每个buffer的大小
        byteBuffers[0] = ByteBuffer.allocate(5);
        byteBuffers[1] = ByteBuffer.allocate(3);

        //等待客户端连接
        SocketChannel socketChannel = serverSocketChannel.accept();
        while (true) {
            int byteRead = 0;
            while (byteRead < 8){

            }
        }
    }
}
